package cn.wzptsoft.tinymallbe.service;

import cn.wzptsoft.tinymallbe.entity.Sku;

import cn.wzptsoft.tinymallbe.repository.SkuRepository;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;

import java.util.*;

@Service
public class SkuService {
    @Autowired
    private SkuRepository skuRepository;


    public List<Optional<Sku>> getsku(String ids) {
        if (ids=="") return null;
        String[] id =ids.split(",");
        List<Optional<Sku>> skus = new ArrayList<>();
        for (int i = 0; i < id.length; i++) {
            Optional<Sku> byId = skuRepository.findById(Long.valueOf(id[i]));
            if (byId.isPresent()){
                skus.add(byId);
            }
        }
        return skus;
    }

}
